<html>

	<head>
		<meta charset="UTF-8">
		<title>打印销售单</title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/print.css">
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/finance.js"></script>
		<style type="text/css">
			/*文字居中*/
			
			.tablecss td {
				text-align: center;
				vertical-align: auto;
			}
			
			.tablecss th {
				width: 50px;
			}
			/*自动换行*/
			
			.tablecss td {
				word-wrap: break-word;
			}
			
			/*重写表格属性*/
			.printtables {
				margin-top: 5px;
			} 
		</style>
	</head>

	<body>
		<div id="printContent">
		</div>

	</body>
	<script type="text/javascript">
		var id = getID();
		function pageprint() {
			if(confirm("是否打印")) {
				print();
			}
		}
		$(document).ready(function(){
			loadRemote();
		});

		function loadRemote() {
			$.ajax({
				type: "get",
				url: RemoteLinkAddress+'/logistics/originalorder/getaorder.do?IDS=' + id,
				dataType: "json",
				success: function(result) {
					CreateHTML(result);
				}
			});
		} 
		
		function CreateHTML(_data){
			var content = "";
			var content_indx = 0;
			var currDate = getNowFormatDate();
			for(var i = 0,len = _data.length;i<len;i++){
				content = "<div class='div_print_info_portait PageNext' style=\"height: auto;width: 820px;\"><h1 align='center'> 绵阳市高水农副产品批发有限公司配送中心 </h1><h1 align='center'> 送货订单</h1><table style=\"margin-left: 5px;width: 800px;\"><tr><th width=\"10%\">购货单位：</th><td width=\"17%\"><input type=\"text\" class=\"print_text_style\" name=\"\" value=\" " + _data[i].CUSTOMER_NAME 
				+ "\" style=\"width: 100%;\" /></td><th width=\"10%\">供货单位：</th><td width=\"13%\"><input type=\"text\" class=\"print_text_style\" name=\"\" value=\"高水蔬菜\" style=\"width: 100%;\" /></td><th width=\"10%\">配送时间：</th><td width=\"13%\"><input type=\"text\" class=\"print_text_style\" name=\"\" value=\"" +_data[i].DISTRIBUTION_DATE
				+"\" style=\"width: 100%;\" /></td><th width=\"10%\">打印时间：</th><td width=\"17%\"><input type=\"text\" class=\"print_text_style\" name=\"\" value=\" "+ currDate +" \" style=\"width: 100%;\" /></td></tr></table><table class=\"altrowstable printtables tablecss\" id=\"SalesTable\" style=\"table-layout:fixed\"><thead><tr><th > 品名 </th><th>订货量</th><th>单价</th><th>金额</th><th>实收数</th><th> 品名 </th><th>订货量</th><th>单价</th><th>金额</th><th>实收数</th><th> 品名 </th><th>订货量</th><th>单价</th><th>金额</th><th>实收数</th></tr></thead><tbody id=\"PrintData\"></tbody><tfoot><tr><td class=\"sum\" >合计：</td>"
							+ "<td></td><td></td><td class=\"row0sum\" ></td><td></td><td></td><td></td><td></td><td class=\"row1sum\" ></td><td></td><td></td><td></td><td></td><td class=\"row2sum\" ></td><td></td></tr>"
						+ "</tfoot></table><table class=\"printtables\" width=\"100%\" frame=\"box\" rules=\"none\" style=\"margin-top: 0\"><tr height=\"30px\"><td>本次配送质量评价：</td><td>________________________</td><td>服务态度：</td><td>________________________</td><td>校检验疫症:</td><td>________________________</td>"
					   	+ "</tr><tr height=\"30px\"><td>送货人（签字）：</td><td>________________________</td><td>学校收货人（签字）：</td><td>________________________</td><td>制单：</td></tr><tr height=\"30px\"><td>咨询电话：</td></tr></table></div>";
				$("#printContent").append(content);
				content_indx ++;
				$("#SalesTable").attr("id", "SalesTable" + content_indx);
				$("#PrintData").attr("id", "PrintData" + content_indx);
				$(".sum").attr("class","sum" + content_indx);
				$(".row0sum").attr("class","row0sum" + content_indx);
				$(".row1sum").attr("class","row1sum" + content_indx);
				$(".row2sum").attr("class","row2sum" + content_indx);
				processDom(_data[i].rows,content_indx);
			}
		}

		//处理DOM表格的DOM节点
		function processDom(_data,_index) {
			var trDom = $("<tr></tr>");
			var tdDom = "";
			var sum0 = 0;
			var sum1 = 0;
			var sum2 = 0;
			var sum = 0;
			var dom = "<td></td><td></td><td></td><td></td><td></td>";
			var s = $("#PrintData" + _index);
			var no = 0;
			for(var i = 0,len = _data.length; i < len; i++) {
				tdDom = "<td>" + _data[i].TRADE_NAME + "</td>";
				tdDom += "<td>" + _data[i].AMOUNT + "</td>";
				tdDom += "<td>" + _data[i].UNIT_PRICE + "</td>";
				tdDom += "<td>" + _data[i].SUM + "</td>";
				tdDom += "<td></td>";
				trDom.append(tdDom);
				if(no == 0){
					sum0 += _data[i].SUM;
				}if(no == 1){
					sum1 += _data[i].SUM;
				}if(no == 2){
					sum2 += _data[i].SUM;
				}
				no++;
				if(no == 3||i == len-1){
					if(no == 1){
						trDom.append(dom + dom);
					}if(no == 2){
						trDom.append(dom);
					}
					s.append(trDom);
					trDom = $("<tr></tr>");
					no = 0;
				}
			}
			sum = sum0 + sum1 + sum2;
			sum0 = parseFloat(sum0).toFixed(2);
			sum1 = parseFloat(sum1).toFixed(2);
			sum2 = parseFloat(sum2).toFixed(2);
			sum = parseFloat(sum).toFixed(2);
			$(".row0sum" + _index).append(sum0);
			$(".row1sum" + _index).append(sum1);
			$(".row2sum" + _index).append(sum2);
			$(".sum" + _index).append(sum);
		}
	</script>

</html>